package com.ziki.account.test;

import lombok.*;

import java.io.Serializable;

@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class R<T> implements Serializable {
    private static final long serialVersionUID = 111111111111111L;
    /**
     * 成功标记
     */
    static Integer SUCCESS = 0;
    /**
     * 失败标记
     */
    static Integer FAIL = 1;

    private int code;

    private String message;

    private T data;

    public static <T> R<T> success() {
        return restResult(null, SUCCESS, "操作成功");
    }

    public static <T> R<T> success(T data) {
        return restResult(data, SUCCESS, "操作成功");
    }

    public static <T> R<T> success(T data, String msg) {
        return restResult(data, SUCCESS, msg);
    }

    public static <T> R<T> failure() {
        return restResult(null, FAIL, "操作失败");
    }

    public static <T> R<T> failure(T data) {
        return restResult(data, FAIL, "操作失败");
    }

    public static <T> R<T> failure(T data, String msg) {
        return restResult(data, FAIL, msg);
    }

    private static <T> R<T> restResult(T data, int code, String msg) {
        return new R<>(code, msg, data);
    }
}